package com.bishe.controller.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {

    public static String md5Password(String password) {
        /*
         * 加密需要使用JDK中提供的类
         */
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");

            byte[] result = digest.digest(password.getBytes());
            StringBuffer buffer = new StringBuffer();

            for (byte b : result) {

                int number = b & 0xff;
                String str = Integer.toString(number);
                if (str.length() == 1) {
                    buffer.append("0");
                }
                buffer.append(str);
            }
            return buffer.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return "";
        }

    }
}
